<?php

namespace app\admin\controller;
use app\BaseController;

class Upload extends BaseController {

  public function image () {

    returnJson(0, '成功！', $categoryList);
  }

  public function upload(){
    // 获取表单上传文件 例如上传了001.jpg
    $files = request()->file();
    
    try {
      validate(['image'=>'fileSize:625000|fileExt:jpg,png'])->check($files);
      $savename = [];
        foreach($files as $file) {
          $savename[] = \think\facade\Filesystem::disk('public')->putFile( 'topic', $file);
        }
      returnJson(0, '成功！', "http://www.tp6.com/storage/".$savename[0]);

    } catch (\think\exception\ValidateException $e) {
      returnJson(-2, $e->getMessage());
    }

  }

  
}